#pragma once

#include "Includes.h"
#include "StateData.h"
#include "Action.h"
#include "Transition.h"
#include "StateResult.h"

class CStateGraph;

/*!
 * \brief CStateBase
 *
 * State base
 */

class CStateBase : public CFSMObject
{
	DECLARE_RTTI_CLASS( CStateBase, CFSMObject::GetRTTI( ) );	

	//================================== METHODS ==============================

public:
	//! Constructor method
	CStateBase(const CStateDataPtr &pStateData);
	//! Constructor method
	CStateBase(const char_t *szName);
	//! Get name state
	CString &GetName();
	//! Enter to state
	void OnEnter(CStateResult *pResult);
	//! Exit from state
	void OnExit(CStateResult *pResult);
	//! Update state
	void OnUpdate(CStateResult *pResult);
	//! Evaluate transitions
	void OnEvualuate(TTransitionList &vTriggeredTransitions);
	//! Add Entry action
	void AddEntryAction(const CActionPtr &pAction);
	//! Add Exit action
	void AddExitAction(const CActionPtr &pAction);
	//! Add process action
	void AddAction(const CActionPtr &pAction);
	//! Add trasition
	void AddTransition(const CTransitionPtr &pTransition);
	//! Get parent
	CStateGraph *GetParent();
	//! Set parent
	void SetParent(CStateGraph *pParent);
	//! Clean state
	virtual void Clean();

protected:
	//! Enter to state
	virtual void DoEnter(CStateResult *pResult);
	//! Exit from state
	virtual void DoExit(CStateResult *pResult);
	//! Update state
	virtual void DoUpdate(CStateResult *pResult);
	//! Evaluate transitions
	virtual void DoEvaluate(TTransitionList &vTriggeredTransitions);

	//================================ DATA MEMBERS ===========================

protected:
	//! Transition list
	TTransitionList m_vTransitions;
	//! Entry action list
	TActionList m_vEntryActions;
	//! Exit action list
	TActionList m_vExitActions;
	//! Process action list
	TActionList m_vActions;
	//! Parent
	CStateGraph *m_pParent;
	//! Name state
	CString m_szName;
};

//============================== TYPE DEFINITIONS =========================

//! State smart pointer
typedef SmartPtr<CStateBase> CStateBasePtr;

//! State smart pointer list
typedef CVector<CStateBasePtr> TStateList;
